package com.icedbrew.appfuel.persistence.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * Base class for persistent entities.
 *
 * @author  arjay.nacion
 * @since   1.0
 */
@Entity
@MappedSuperclass
public abstract class BaseEntity implements Serializable {

    @Id
    @Column
    private Long id;

    @Temporal(value = TemporalType.TIMESTAMP)
    @Column(name = "date_created")
    private Date dateCreated;

    @Temporal(value = TemporalType.TIMESTAMP)
    @Column(name = "date_updated")
    private Date dateUpdated;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Date getDateUpdated() {
        return dateUpdated;
    }

    public void setDateUpdated(Date dateUpdated) {
        this.dateUpdated = dateUpdated;
    }

    /**
     * This implementation relies only on the value of
     * the <code>id</code>, the primary key of the record
     * this entity represents. Sub-classes are encouraged
     * to override this as much as possible and to use the
     * appropriate non-null and unique fields.
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof BaseEntity)) return false;

        BaseEntity that = (BaseEntity) o;

        if (!id.equals(that.id)) return false;

        return true;
    }

    /**
     * This implementation relies only on the value of
     * the <code>id</code>, the primary key of the record
     * this entity represents. Sub-classes are encouraged
     * to override this as much as possible and to use the
     * appropriate non-null and unique fields.
     */
    @Override
    public int hashCode() {
        return id.hashCode();
    }
}
